package thread;

/*
 * @author zzr
 * @date: 2025/04/10  21:03
 * @description:
 */
public class ThreadDemo45 {
    private static int sum = 0;

    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(new Runnable() {
            @Override
            public void run() {
                int result = 0;
                for (int i = 1; i < 1000; i++) {
                    result += i;
                }
                sum = result;
            }
        });
        t.start();
        t.join();
        // 在主线程中获取到计算结果
        // 此处要获取到结果，就需要专门搞一个成员变量，来保存上面的计算结果
        System.out.println("sum = " + sum);
    }
}
